import { prisma } from '@/lib/prisma/client'
import { NextResponse } from 'next/server'

export async function GET() {
  try {
    const [devices, scenes] = await Promise.all([
      prisma.device.findMany(),
      prisma.scene.findMany()
    ])

    const stats = {
      deviceCount: devices.length,
      sceneCount: scenes.length,
      activeSceneCount: scenes.filter(scene => scene.isActive).length,
      deviceStatus: {
        online: devices.filter(device => device.status === 'online').length,
        offline: devices.filter(device => device.status === 'offline').length
      }
    }

    return NextResponse.json(stats)
  } catch (error) {
    console.error('获取统计数据失败:', error)
    return NextResponse.json(
      { error: '获取统计数据失败' },
      { status: 500 }
    )
  }
} 